﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RepositorySystem.Filter
{
    /// <summary>
    /// 自定义的action过滤器
    /// </summary>
    public class CustomActionFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            //Microsoft.AspNetCore.Http.HttpContext

            string jsonUserInfo = context.HttpContext.Session.GetString("UserInfo");
            //判断session中是否有userInfo
            //如果有就接着访问这个视图
            if (string.IsNullOrEmpty(jsonUserInfo))
            {
                //如果没有跳转到登录页
                //context.HttpContext.Response.Redirect("/first/login");
                context.Result = new RedirectResult("/Login/LoginView");
            }

            //Console.WriteLine("OnActionExecuting");
        }

        public override void OnActionExecuted(ActionExecutedContext context)
        {

            //Console.WriteLine("OnActionExecuted");
        }
    }
}
